const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
const {formatTime} = require('../../utils/util.js');
Page({
  data: {
    Shareimg:'',
    id:'',
    path:'',
    scene:'',
  },
  onLoad: function (options) {
    if(!wx.getStorageSync('logintoken')){
      app.goLogin()
    }
    console.log(options)
    if(options.id){
      this.setData({
        id:options.id,
        scene:options.scene,
        path:options.path
      })
      this.makeShare()
    }
    
  },
  makeShare(){
    var that=this;
    wx.showLoading({
      title: '海报生成中',
      mask: true,
    })
    // var path=that.data.path;
    // var path1=that.data.path.split('?')[0];
    // var scene=that.data.path.split('?')[1];
    var scene=JSON.parse(this.data.scene);
    var urlWithArgs = ''

    for(var key in scene){
        var value = scene[key]
        urlWithArgs += key + '=' + value + '&'
    }


    Controller.makeShare({jobId:that.data.id,path:this.data.path,scene:encodeURIComponent(urlWithArgs)}).then(res=>{
      if(res.data.baseData){
        that.setData({
          Shareimg:res.data.baseData
        })
      }
      wx.hideLoading();
    }).catch(res=>{
      wx.hideLoading();
    })
  },
  saveImgBtn() {
    setTimeout(()=>{
      app.saveImg(this.data.Shareimg)
    },800)
  },

  onShareAppMessage: function () {

  }
})
